package com.example.demo.common;

import org.apache.naming.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-11-21
 * Time: 11:29
 */
public class TimeTransfer {
    public static long convertTimeToNumber(String timeString) {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date = format.parse(timeString);
            // 精确到分钟
            return date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return -1;
        }
    }
    public static long convertTimeToNumber(long currentTime) {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String string =format.format(currentTime);
            Date date = format.parse(string);
            // 精确到分钟
            return date.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
            return -1;
        }
    }

    public static Date convertTimeToDate(String timeString) {

        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = format.parse(timeString);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
}
